package com.tuantuan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.tuantuan.common.base.BaseController;
import com.tuantuan.common.base.param.IDParam;
import com.tuantuan.common.base.param.QueryParam;
import com.tuantuan.common.base.result.IDVo;
import com.tuantuan.common.base.result.Responses;
import com.tuantuan.common.utils.BeanCopyUtil;
import com.tuantuan.model.entity.TaxDO;
import com.tuantuan.service.ITaxService;
import com.tuantuan.model.vo.TaxVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: 王钦民
 * @date : 2020-10-29
 * @description: 仰天大笑出门去，我辈岂是蓬蒿人
 */
@Slf4j
@RestController
@RequestMapping("/taxDO")
@Api(tags = "企业营业执照申请-公安登记-公安备案信息")
@ApiSupport(author = "王钦民", order = 999)
public class TaxController extends BaseController {

    @Autowired
    private ITaxService iTaxService;

    /**
     * 新增
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增", notes = "添加企业营业执照申请-公安登记-公安备案信息信息")
    @ApiOperationSupport(author = "王钦民", order = 1, ignoreParameters = {"id", "createTime", "updateTime"})
    public Responses<IDVo> insertTax(@Valid @RequestBody TaxDO taxDO) {
        iTaxService.save(taxDO);
        return success(new IDVo(taxDO.getId().toString()));
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperationSupport(author = "王钦民", order = 2)
    @ApiOperation(value = "删除", notes = "根据id删除数据")
    public Responses<Boolean> deleteTax(@Valid @RequestBody IDParam idParam) {
        boolean flag = iTaxService.removeById(idParam.getId());
        return success(flag);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "根据id修改数据")
    @ApiOperationSupport(author = "王钦民", order = 3, ignoreParameters = {"createTime", "updateTime"})
    public Responses<Boolean> updateTax(@Valid @RequestBody TaxDO taxDO) {
        boolean flag = iTaxService.updateById(taxDO);
        return success(flag);
    }

    /**
     * 查询
     */
    @PostMapping("/info")
    @ApiOperationSupport(author = "王钦民", order = 5)
    @ApiOperation(value = "查询", notes = "根据id查看详情")
    public Responses<TaxVO> getTax(@Valid @RequestBody IDParam idParam) {
        TaxVO taxVO = BeanCopyUtil.copy(iTaxService.getById(idParam.getId()), TaxVO.class);
        return success(taxVO);
    }

    /**
     * 所有列表
     */
    @PostMapping("/list")
    @ApiOperationSupport(author = "王钦民", order = 6)
    @ApiOperation(value = "所有列表", notes = "查询所有数据")
    public Responses<List<TaxDO>> list() {
        List<TaxDO> list = iTaxService.list();
        return success(list);
    }

    /**
     * 分页列表
     */
    @PostMapping("/listPageTax")
    @ApiOperation(value = "分页列表", notes = "分页列表展示(默认创建时间降序排序)")
    @ApiOperationSupport(author = "王钦民", order = 7)
    public Responses<Page<TaxDO>> listPageTax(@Valid @RequestBody(required = false) QueryParam queryParam) {
        Page<TaxDO> paging = iTaxService.listPageTax(queryParam);
        return success(paging);
    }
}

